package com.hw.paltfrom.service.mainscreen;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import java.util.Random;

import java.sql.Timestamp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.mapper.HwDataOverrunstationMapper;
import com.hw.paltfrom.mapper.ViewOverrunStationMapper;
import com.hw.paltfrom.pack.ResponseResult;
import com.hw.paltfrom.pojo.HwDataOverrunstation;
import com.hw.paltfrom.pojo.ViewOverrunStationJCZSByMinute;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.DateTimeUtil;

@Service
public class OverRunStationStreamServer {
	
	@Autowired
	private HwDataOverrunstationMapper hdorsMapper;
	@Autowired
	private ViewOverrunStationMapper viewmapper;
	
	public Map<String, Object> query() {
		long afterMinute = DateTimeUtil.getAfterMinute(-1);
		Timestamp startTime = new Timestamp(afterMinute);
		Timestamp endTime = new Timestamp(System.currentTimeMillis());
		Wrapper<HwDataOverrunstation> wrapper=new EntityWrapper<HwDataOverrunstation>();
		wrapper.between("D_JCSJ", startTime, endTime);
		Integer count = hdorsMapper.selectCount(wrapper);
		
		Random random = new Random();
		count = random.nextInt(100);
		return ResponseResult.successNotice(HWSystemCode.SUCCESS, count);
	}
	
	
	public Map<String, Object> queryHistory() {
		Wrapper<ViewOverrunStationJCZSByMinute> wrapper=new EntityWrapper<ViewOverrunStationJCZSByMinute>();
		Long afterMinute = DateTimeUtil.getAfterMinute(-30); 
		wrapper.between("StartTime", new Timestamp(afterMinute),  new Timestamp(System.currentTimeMillis()) );
		wrapper.orderBy("StartTime",true);
		List<ViewOverrunStationJCZSByMinute> selectList = viewmapper.selectList(wrapper);
		return ResponseResult.successNotice(HWSystemCode.SUCCESS, selectList);
	}
}
